// 根据公司分组，查询
import {mrhzApi, zdfpApi, zdfpApi as selectPage} from "../../services/basic";
import Dictionary from "../../services/dictionary";
import {formatNumber} from "../../utils/math";
// import {Select} from "../../components/Select";
import React from "react";
import withBasePage from "../../components/BaseComponent/withBasePage";
import CompanyGroup from "../../components/CompanyGroup";

// 要显示的form表单
const formItemList = []
// 显示的按钮
const buttons = ["query", "export",];
// 表格列信息
const columns = [
    {
        title: '公司名称',
        dataIndex: 'gsmc',
        sumName: "合计",
        sorter: true
    },
    {
        title: '到店未成交',
        dataIndex: 'ddwcj',
        sorter: true
    },
    {
        title: '到店已成交',
        dataIndex: 'ddycj',
        sorter: true
    },
    {
        title: '异公司到店',
        dataIndex: 'ygsdd',
        sorter: true
    },
    {
        title: '异公司已成交',
        dataIndex: 'ygscj',
        sorter: true
    },
    {
        title: '到店总数量',
        dataIndex: 'zdd',
        tip: "到店已成交+到店未成交+异公司到店已成交+异公司到店未成交",
        // 已成交、未成交、异公司全算
        render(_, record) {
            return Number(record["ddwcj"]) + Number(record["ddycj"]) + Number(record["ygsdd"]) + Number(record["ygscj"])
        },
        sorter: true,
        formula: "=SUM({{ddwcj}},{{ddycj}},{{ygsdd}},{{ygscj}})"
    },
    {
        title: '有效留资',
        dataIndex: 'yxlz',
        sorter: true
    },
    {
        title: '到店比',
        tip: '到店比=有效留资数/总到店数',
        dataIndex: 'ddb',
        render: (_, record) => {
            const zdd = Number(record.ddwcj) + Number(record.ddycj) + Number(record.ygscj) + Number(record.ygsdd)
            if (!zdd) return 0
            return (Number(record.yxlz) / Number(zdd)).toFixed(2)
        },
        numFmt: "0.00",
        formula: "=IFERROR({{yxlz}}/{{zdd}}, 0)",
        sorter: true
    },
    {
        title: '成交总数量',
        dataIndex: 'cjSum',
        render(_, record) {
            return Number(record["ddycj"]) + Number(record["ygscj"])
        },
        sorter: true,
        formula: "=SUM({{ddycj}},{{ygscj}})"
    },
    {
        title: '未成交总数',
        dataIndex: 'wcjSum',
        render(_, record) {
            return Number(record["ddwcj"]) + Number(record["ygsdd"])
        },
        sorter: true,
        formula: "=SUM({{ddwcj}},{{ygsdd}})"
    },
    {
        title: '成交金额',
        dataIndex: 'cjje',
        sorter: true
    },
    {
        title: '成交率(%)',
        tip: '成交总数量 ÷ 到店总数量 * 100%',
        dataIndex: 'wxcjl',
        sorter: true,
        numFmt: "0.00",
        formula: "=IFERROR({{cjSum}}/{{zdd}}, 0)",
        render: (_, record) => {
            const zdd = Number(record["ddwcj"]) + Number(record["ddycj"]) + Number(record["ygsdd"]) + Number(record["ygscj"])
            if (!zdd) return 0
            const cjSum = Number(record["ddycj"]) + Number(record["ygscj"])
            return formatNumber(cjSum / zdd * 100)
        }
    },
    {
        title: '客单价',
        tip: '客单价 = 成交金额 ÷ 成交总数量',
        formula: "=IFERROR({{cjje}}/{{cjSum}}, 0)",
        dataIndex: 'wxkdj',
        sorter: true,
        render: (_, record) => {
            const cjSum = Number(record["ddycj"]) + Number(record["ygscj"])
            if (!cjSum) return 0
            return formatNumber(Number(record.cjje) / cjSum)
        }
    },
    {
        title: '到店间隔天数',
        tip: "留资日期与客户到店日期的间隔天数",
        dataIndex: 'ddpjcz',
        sumName: "",
        sorter: true
    },
]

export default withBasePage({
    state: {
        formItemList,
        buttons,
        // columns,
        filename: "销售导购成交统计",
        queryAll: true,
        sumRow: true,
    },
    pageLoad: false,
    columns,
    queryApi: mrhzApi.selectPagewxcjByWxkf,
    // queryApi: mrhzApi.selectPagewxcj,
    hasLzModal: false
})(() => null);
